<template>
  <!--更新项目状态start -->
  <el-dialog
    v-dialogDrag
    :title="dialogTitle"
    :close-on-click-modal="false"
    :visible.sync="dialogVisible"
    class="dialogStyleSmall"
    :before-close="cancel"
  >
    <el-form
      v-if="dialogVisible"
      ref="addForm"
      class="dialog-form"
      :model="formData"
      :rules="rules"
      label-width="80px"
    >
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="项目名称" prop="proName">
            <el-input v-model="formData.proName" readonly size="medium" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="项目状态" prop="status">
            <el-select v-model="formData.status" size="medium">
              <el-option
                v-for="dict in proStatus"
                :key="dict.dictValue"
                size="medium"
                :label="dict.dictLabel"
                :value="dict.dictValue"
                :disabled="dict.disabled"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <DialogFooter />
    </div>
  </el-dialog>
  <!--更新项目状态end -->
</template>

<script>
// 页面接口
import { changeStatus } from '@/api/projectManage/project/index'
// 附件上传
// dialog-footer
import DialogFooter from '@/components/Common/Btns/DialogFooter/index'
export default {
  components: {
    DialogFooter
  },
  data() {
    return {
      /* 新增 start*/
      dialogTitle: '', // 弹层标题
      dialogVisible: false, // 弹层是否显示
      formData: { // 新增数据
        id: '', // 项目id
        proName: '', // 项目名称
        status: '' // 状态
      },
      // 表单验证规则
      rules: {
        status: [
          { required: true, message: '请选择项目状态', trigger: 'change' }
        ]
      },
      // 项目状态
      proStatus: [
        {
          dictLabel: '未开始',
          dictValue: '0',
          disabled: false
        },
        {
          dictLabel: '进行中',
          dictValue: '1',
          disabled: false
        },
        {
          dictLabel: '已结束',
          dictValue: '2',
          disabled: false
        },
        {
          dictLabel: '暂停中',
          dictValue: '3',
          disabled: false
        }
      ]
      /* 新增 end*/
    }
  },
  methods: {
    /* 新增/编辑弹层 start*/
    // 新增/编辑
    handleAdd(title, obj) {
      this.emptyAddForm() // 清空
      this.dialogTitle = title
      this.formData = { ...obj }
      this.dialogVisible = true
      if (obj.status === '1') {
        this.proStatus[0].disabled = true
      } else if (obj.status === '2') {
        this.proStatus[0].disabled = true
        this.proStatus[1].disabled = true
      } else {
        this.proStatus.map(item => {
          item.disabled = false
        })
      }
    },
    // 取消按钮
    cancel() {
      this.dialogVisible = false
      this.emptyAddForm()
    },
    // 提交按钮
    submitForm() {
      this.$refs['addForm'].validate(async valid => {
        if (valid) {
          await changeStatus(this.formData)
          this.msgSuccess('保存成功')
          this.cancel()
          this.$parent.getList()
        }
      })
    },
    // 表单重置
    emptyAddForm() {
      this.resetForm('addForm')
      this.formData.id = ''
    }
    /* 新增弹层 end*/
  }

}
</script>

<style>

</style>
